var Adv_skd=require("./Adv_skd")

var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2Hts = require("Hts");
var $2WeChatConstant = require("WeChatConstant");
var $2ADManager = require("ADManager");
var $2pvzChannel = require("pvzChannel");
var $2AudioManager = require("AudioManager");
var $2DataManager = require("DataManager");
var $2ExcelManager = require("ExcelManager");
var $2UIManager = require("UIManager");
var $2UserDataManager = require("UserDataManager");
var $2TaSdk = require("TaSdk");
var $2MyUtils = require("MyUtils");
var $2MenuUI = require("MenuUI");
var $2NoCoinUI = require("NoCoinUI");
var $2RewardUI = require("RewardUI");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_DrawUI = /* */function (_cc$Component18) {
  babel_inherits(b, _cc$Component18);
  var _super20 = babel_createSuper(b);
  function b() {
    var _this50;
    babel_classCallCheck(this, b);
    _this50 = _super20.apply(this, arguments);
    _this50.btn1 = null;
    _this50.btn2 = null;
    _this50.btn3 = null;
    _this50.btn4 = null;
    _this50.ball = null;
    _this50.ball2 = null;
    _this50.guidePanel = null;
    _this50.goldDraw = null;
    _this50.diamondDraw = null;
    _this50.normalNode = null;
    _this50.videoNode = null;
    _this50.line = null;
    _this50.canDraw = true;
    _this50.guideString = ["金币抽奖大概率得到稀有植物碎片", "钻石抽奖不仅能获得高级植物碎片，还有概率得到完整的植物"];
    _this50.rewardArr = [];
    _this50.maxRare = 0;
    _this50.highLight = null;
    _this50.guideFinger = null;
    _this50.guideStep = -1;
    return _this50;
  }
  babel_createClass(b, [{
    key: "onLoad",
    value: function onLoad() {
      Adv_skd.default.instance.hideAllAdv();
      Adv_skd.default.instance.showInterstitialAd();
      Adv_skd.default.instance.showGridAdRight();
      Adv_skd.default.instance.showGridAdLeft();

      $2TaSdk.default.instance.postEvent("System", {
        system: "植物升级"
      });
      this.btn1.on(cc.Node.EventType.TOUCH_START, this.onClickStart, this);
      this.btn1.on(cc.Node.EventType.TOUCH_END, this.onClickEnd, this);
      this.btn1.on(cc.Node.EventType.TOUCH_CANCEL, this.onClickEnd, this);
      this.btn2.on(cc.Node.EventType.TOUCH_START, this.onClickStart, this);
      this.btn2.on(cc.Node.EventType.TOUCH_END, this.onClickEnd, this);
      this.btn2.on(cc.Node.EventType.TOUCH_CANCEL, this.onClickEnd, this);
      this.btn3.on(cc.Node.EventType.TOUCH_START, this.onClickStart, this);
      this.btn3.on(cc.Node.EventType.TOUCH_END, this.onClickEnd, this);
      this.btn3.on(cc.Node.EventType.TOUCH_CANCEL, this.onClickEnd, this);
      this.btn4.on(cc.Node.EventType.TOUCH_START, this.onClickStart, this);
      this.btn4.on(cc.Node.EventType.TOUCH_END, this.onClickEnd, this);
      this.btn4.on(cc.Node.EventType.TOUCH_CANCEL, this.onClickEnd, this);
      this.guidePanel.zIndex = 99;
      this.initPlatform();
      this.registerEvent();
      this.refreshBtn();
    }
  }, {
    key: "refreshBtn",
    value: function refreshBtn() {
      if ($2UserDataManager.default.instance.diamond < 360 && $2UserDataManager.default.instance.videoDrawTimes < 5) {
        this.normalNode.active = false;
        this.videoNode.active = true;
        this.line.active = true;
      } else {
        this.normalNode.active = true;
        this.videoNode.active = false;
        this.line.active = false;
      }
    }
  }, {
    key: "registerEvent",
    value: function registerEvent() {
      this.node.on("draw", this.draw, this);
      this.node.on("onClickCloseBtn", this.onClickCloseBtn, this);
    }
  }, {
    key: "showGuideToast",
    value: function showGuideToast(e) {
      this.guidePanel.active = true;
      this.guidePanel.getComponentInChildren(cc.Label).string = e;
    }
  }, {
    key: "onClickStart",
    value: function onClickStart(e) {
      this.canDraw && cc.tween(e.currentTarget).to(.15, {
        y: 5
      }).start();
    }
  }, {
    key: "onClickEnd",
    value: function onClickEnd(e) {
      if (this.canDraw) {
        cc.Tween.stopAllByTarget(e.currentTarget);
        e.currentTarget.y = 15;
        this.draw(e.currentTarget.name);
      }
    }
  }, {
    key: "draw",
    value: function draw(e) {
      var _this51 = this;
      this.canDraw = false;
      this.rewardArr = [];
      this.maxRare = 0;
      switch (e) {
        case "btn1":
          if ($2UserDataManager.default.instance.gold < 2e3) {
            $2Hts.default.instance.eventReport("金币单抽失败");
            $2UIManager.default.instance.openUI("NoCoinUI", 50).getComponent($2NoCoinUI.default).init(0);
            return void (this.canDraw = true);
          }
          $2Hts.default.instance.eventReport("金币单抽成功");
          $2TaSdk.default.instance.postEvent("Luckychest", {
            Type_chest: 1,
            Type_num: 1
          });
          $2AudioManager.default.instance.playEffect("LotteryEff");
          $2UserDataManager.default.instance.gold -= 2e3;
          this.getReward(0);
          this.goldAni();
          break;
        case "btn2":
          if ($2UserDataManager.default.instance.gold < 18e3) {
            this.canDraw = true;
            $2Hts.default.instance.eventReport("金币十连失败");
            return void $2UIManager.default.instance.openUI("NoCoinUI", 50).getComponent($2NoCoinUI.default).init(0);
          }
          $2Hts.default.instance.eventReport("金币十连成功");
          $2TaSdk.default.instance.postEvent("Luckychest", {
            Type_chest: 1,
            Type_num: 10
          });
          for (var _e23 = 0; _e23 < 10; _e23++) {
            this.getReward(0);
          }
          $2AudioManager.default.instance.playEffect("LotteryEff");
          $2UserDataManager.default.instance.gold -= 18e3;
          this.goldAni();
          break;
        case "btn3":
          if ($2UserDataManager.default.instance.diamond < 40) {
            this.canDraw = true;
            $2UIManager.default.instance.openUI("NoCoinUI", 50).getComponent($2NoCoinUI.default).init(1);
            return void $2Hts.default.instance.eventReport("钻石单抽失败");
          }
          $2Hts.default.instance.eventReport("钻石单抽成功");
          $2TaSdk.default.instance.postEvent("Luckychest", {
            Type_chest: 2,
            Type_num: 1
          });
          $2UserDataManager.default.instance.diamond -= 40;
          $2AudioManager.default.instance.playEffect("LotteryEff");
          if ($2DataManager.default.instance.drawGuide) {
            this.rewardArr.push({
              rewardType: "a",
              rare: 1,
              number: 20,
              plantID: 11
            });
            this.maxRare = 4;
            $2UserDataManager.default.instance.setPlantChip(11, 20);
          } else {
            this.getReward(1);
          }
          this.diamondAni();
          break;
        case "btn4":
          var _t17 = function _t17() {
            $2AudioManager.default.instance.playEffect("LotteryEff");
            for (var _e24 = 0; _e24 < 10; _e24++) {
              _this51.getReward(1);
            }
            $2UserDataManager.default.instance.videoDrawTimes++;
            _this51.diamondAni();
            _this51.refreshBtn();
          };
          var _a14 = function _a14() {};
          var _n24 = function _n24() {
            _this51.canDraw = true;
          };
          if ($2UserDataManager.default.instance.diamond < 360) {
            return void ($2UserDataManager.default.instance.videoDrawTimes < 5 ? $2pvzChannel.pvzChannel.instance().showVideo({
              sucCall: _t17,
              failCall: _a14,
              endCall: _n24
            }) : ($2UIManager.default.instance.openUI("NoCoinUI", 50).getComponent($2NoCoinUI.default).init(1), $2Hts.default.instance.eventReport("钻石十连失败"), this.canDraw = true));
          }
          $2UserDataManager.default.instance.videoDrawTimes--;
          $2UserDataManager.default.instance.diamond -= 360;
          _t17();
      }
      this.refreshBtn();
    }
  }, {
    key: "goldAni",
    value: function goldAni() {
      var _this52 = this;
      this.goldDraw.setAnimation(0, "choujiang", false);
      var e = this.maxRare;
      e > 1 && e--;
      this.goldDraw.setCompleteListener(function () {
        _this52.goldDraw.setAnimation(0, "chujiang" + e, false);
        _this52.goldDraw.setCompleteListener(function () {
          _this52.ball.active = true;
          _this52.goldDraw.setCompleteListener(null);
          _this52.ball.getComponent(sp.Skeleton).setAnimation(0, "kaiqiu" + e, false);
          _this52.goldDraw.setAnimation(0, "daiji", true);
          _this52.ball.getComponent(sp.Skeleton).setCompleteListener(function () {
            $2UIManager.default.instance.openUI("RewardUI", 30).getComponent($2RewardUI.default).init(_this52.rewardArr);
            _this52.ball.getComponent(sp.Skeleton).setCompleteListener(null);
            _this52.ball.active = false;
            _this52.canDraw = true;
          });
        });
      });
    }
  }, {
    key: "diamondAni",
    value: function diamondAni() {
      var _this53 = this;
      this.diamondDraw.setAnimation(0, "choujiang", false);
      var e = this.maxRare;
      e > 1 && e--;
      this.diamondDraw.setCompleteListener(function () {
        _this53.diamondDraw.setAnimation(0, "chujiang" + e, false);
        _this53.diamondDraw.setCompleteListener(function () {
          _this53.ball2.active = true;
          _this53.diamondDraw.setCompleteListener(null);
          _this53.ball2.getComponent(sp.Skeleton).setAnimation(0, "kaiqiu" + e, false);
          _this53.diamondDraw.setAnimation(0, "daiji", true);
          _this53.ball2.getComponent(sp.Skeleton).setCompleteListener(function () {
            $2UIManager.default.instance.openUI("RewardUI", 30).getComponent($2RewardUI.default).init(_this53.rewardArr);
            _this53.ball2.getComponent(sp.Skeleton).setCompleteListener(null);
            _this53.ball2.active = false;
            _this53.canDraw = true;
          });
        });
      });
    }
  }, {
    key: "getReward",
    value: function getReward(e) {
      var t;
      var a;
      var n = 0;
      var i = {
        rewardType: "a",
        rare: 0,
        number: 0,
        plantID: 0
      };
      for (0 == e ? (t = $2MyUtils.MyUtils.getRandomInt(1, $2DataManager.default.instance.maxWeight1 + 1), a = $2DataManager.default.instance.drawWeight1) : (t = $2MyUtils.MyUtils.getRandomInt(1, $2DataManager.default.instance.maxWeight2 + 1), a = $2DataManager.default.instance.drawWeight2); t > a[n];) {
        n++;
      }
      n++;
      console.log("ran===", t);
      i.rewardType = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.lotteryTable)[n].rewardType;
      i.rare = $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.lotteryTable)[n].rare;
      i.rare > this.maxRare && (this.maxRare = i.rare);
      var s = $2MyUtils.MyUtils.getRandomInt($2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.lotteryTable)[n].rewardNumber[0], $2ExcelManager.ExcelMgr.instance.GetExcelObject($2ExcelManager.TableName.lotteryTable)[n].rewardNumber[1] + 1);
      i.number = s;
      var o = $2MyUtils.MyUtils.getArrRandomValue($2DataManager.default.instance["rare" + i.rare + "Array"]);
      i.plantID = o;
      if ("a" == i.rewardType) {
        $2UserDataManager.default.instance.setPlantChip(o, s);
      } else {
        $2UserDataManager.default.instance.getPlant(o);
      }
      this.rewardArr.push(i);
      $2UserDataManager.default.instance.taskInfo[3].progress++;
    }
  }, {
    key: "onClickCloseBtn",
    value: function onClickCloseBtn() {
      Adv_skd.default.instance.hideAllAdv();

      if ($2DataManager.default.instance.drawGuide) {
        $2UIManager.default.instance.showToast("请先完成引导");
      } else {
        $2UIManager.default.instance.closeUI("DrawUI");
        $2UIManager.default.instance.uiList.MenuUI.getComponent($2MenuUI.default).showNode();
        if ($2ADManager.default.instance.sdkType == $2ADManager.SDK_TYPE.WeChat) {
          $2MyUtils.MyUtils.probability($2WeChatConstant.default.mainInster) && $2ADManager.default.instance.showInsert(), $2ADManager.default.instance.hideNative(1), $2ADManager.default.instance.showNative(0);
        }
      }
    }
  }, {
    key: "initPlatform",
    value: function initPlatform() {
      switch ($2ADManager.default.instance.sdkType) {
        case $2ADManager.SDK_TYPE.WeChat:
          $2ADManager.default.instance.hideNative(0);
          $2ADManager.default.instance.showNative(1);
      }
    }
  }]);
  return b;
}(cc.Component);
cc__decorate([ccp_property(cc.Node)], def_DrawUI.prototype, "btn1", undefined);
cc__decorate([ccp_property(cc.Node)], def_DrawUI.prototype, "btn2", undefined);
cc__decorate([ccp_property(cc.Node)], def_DrawUI.prototype, "btn3", undefined);
cc__decorate([ccp_property(cc.Node)], def_DrawUI.prototype, "btn4", undefined);
cc__decorate([ccp_property(cc.Node)], def_DrawUI.prototype, "ball", undefined);
cc__decorate([ccp_property(cc.Node)], def_DrawUI.prototype, "ball2", undefined);
cc__decorate([ccp_property(cc.Node)], def_DrawUI.prototype, "guidePanel", undefined);
cc__decorate([ccp_property(sp.Skeleton)], def_DrawUI.prototype, "goldDraw", undefined);
cc__decorate([ccp_property(sp.Skeleton)], def_DrawUI.prototype, "diamondDraw", undefined);
cc__decorate([ccp_property(cc.Node)], def_DrawUI.prototype, "normalNode", undefined);
cc__decorate([ccp_property(cc.Node)], def_DrawUI.prototype, "videoNode", undefined);
cc__decorate([ccp_property(cc.Node)], def_DrawUI.prototype, "line", undefined);
def_DrawUI = cc__decorate([ccp_ccclass], def_DrawUI);
exports.default = def_DrawUI;